package com.zoffy.zoffyapi.commen;

import com.zoffy.zoffyapi.exception.BusinessException;
import com.zoffy.zoffyapi.exception.ErrorCode;

public class ThrowUtils {

    /**
     * 条件成立则抛异常
     *
     * @param condition 抛出异常条件
     * @param runtimeException 抛出的异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition 抛出异常条件
     * @param errorCode 抛出的异常码
     */
    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition 抛出异常条件
     * @param errorCode 抛出的异常码
     * @param message 异常携带信息
     */
    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }
}
